<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QHttpMultiPart Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QHttpMultiPart Class Reference<br /><sup><sup>[<a href="qtnetwork.html">QtNetwork</a> module]</sup></sup></h1><p>The QHttpMultiPart class resembles a MIME multipart message to
be sent over HTTP. <a href="#details">More...</a></p>

<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qhttpmultipart.html#ContentType-enum">ContentType</a></b> { MixedType, RelatedType, FormDataType, AlternativeType }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qhttpmultipart.html#QHttpMultiPart">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qhttpmultipart.html#QHttpMultiPart-2">__init__</a></b> (<i>self</i>, ContentType&#160;<i>contentType</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qhttpmultipart.html#append">append</a></b> (<i>self</i>, QHttpPart&#160;<i>httpPart</i>)</li><li><div class="fn" />QByteArray <b><a href="qhttpmultipart.html#boundary">boundary</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qhttpmultipart.html#setBoundary">setBoundary</a></b> (<i>self</i>, QByteArray&#160;<i>boundary</i>)</li><li><div class="fn" /><b><a href="qhttpmultipart.html#setContentType">setContentType</a></b> (<i>self</i>, ContentType&#160;<i>contentType</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QHttpMultiPart class resembles a MIME multipart message to
be sent over HTTP.</p>
<p>The QHttpMultiPart resembles a MIME multipart message, as
described in RFC 2046, which is to be sent over HTTP. A multipart
message consists of an arbitrary number of body parts (see <a href="qhttppart.html">QHttpPart</a>), which are separated by a unique
boundary. The boundary of the QHttpMultiPart is constructed with
the string "boundary_.oOo.<a href="index.html">_</a>" followed by
random characters, and provides enough uniqueness to make sure it
does not occur inside the parts itself. If desired, the boundary
can still be set via <a href="qhttpmultipart.html#setBoundary">setBoundary</a>().</p>
<p>As an example, consider the following code snippet, which
constructs a multipart message containing a text part followed by
an image part:</p>
<pre class="cpp">
 <span class="type">QHttpMultiPart</span> <span class="operator">*</span>multiPart <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QHttpMultiPart</span>(<span class="type">QHttpMultiPart</span><span class="operator">.</span>FormDataType);

 <span class="type"><a href="qhttppart.html">QHttpPart</a></span> textPart;
 textPart<span class="operator">.</span>setHeader(<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span><span class="operator">.</span>ContentDispositionHeader<span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(<span class="string">"form-data; name=\"text\""</span>));
 textPart<span class="operator">.</span>setBody(<span class="string">"my text"</span>);

 <span class="type"><a href="qhttppart.html">QHttpPart</a></span> imagePart;
 imagePart<span class="operator">.</span>setHeader(<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span><span class="operator">.</span>ContentTypeHeader<span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(<span class="string">"image/jpeg"</span>));
 imagePart<span class="operator">.</span>setHeader(<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span><span class="operator">.</span>ContentDispositionHeader<span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(<span class="string">"form-data; name=\"image\""</span>));
 <span class="type"><a href="qfile.html">QFile</a></span> <span class="operator">*</span>file <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qfile.html">QFile</a></span>(<span class="string">"image.jpg"</span>);
 file<span class="operator">-</span><span class="operator">&gt;</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly);
 imagePart<span class="operator">.</span>setBodyDevice(file);
 file<span class="operator">-</span><span class="operator">&gt;</span><a href="qobject.html#setParent">setParent</a>(multiPart); <span class="comment">// we cannot delete the file now, so delete it with the multiPart</span>

 multiPart<span class="operator">-</span><span class="operator">&gt;</span><a href="qhttpmultipart.html#append">append</a>(textPart);
 multiPart<span class="operator">-</span><span class="operator">&gt;</span><a href="qhttpmultipart.html#append">append</a>(imagePart);

 <span class="type"><a href="qurl.html">QUrl</a></span> url(<span class="string">"http://my.server.tld"</span>);
 <span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span> request(url);

 <span class="type"><a href="qnetworkaccessmanager.html">QNetworkAccessManager</a></span> manager;
 <span class="type"><a href="qnetworkreply.html">QNetworkReply</a></span> <span class="operator">*</span>reply <span class="operator">=</span> manager<span class="operator">.</span>post(request<span class="operator">,</span> multiPart);
 multiPart<span class="operator">-</span><span class="operator">&gt;</span><a href="qobject.html#setParent">setParent</a>(reply); <span class="comment">// delete the multiPart with the reply</span>
 <span class="comment">// here connect signals etc.</span>
</pre><hr /><h2>Type Documentation</h2><h3 class="fn"><a name="ContentType-enum" />QHttpMultiPart.ContentType</h3><p>List of known content types for a multipart subtype as described
in RFC 2046 and others.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QHttpMultiPart.MixedType</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">corresponds to the "multipart/mixed" subtype,
meaning the body parts are independent of each other, as described
in RFC 2046.</td>
</tr>
<tr>
<td class="topAlign"><tt>QHttpMultiPart.RelatedType</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">corresponds to the "multipart/related"
subtype, meaning the body parts are related to each other, as
described in RFC 2387.</td>
</tr>
<tr>
<td class="topAlign"><tt>QHttpMultiPart.FormDataType</tt></td>
<td class="topAlign"><tt>2</tt></td>
<td class="topAlign">corresponds to the "multipart/form-data"
subtype, meaning the body parts contain form elements, as described
in RFC 2388.</td>
</tr>
<tr>
<td class="topAlign"><tt>QHttpMultiPart.AlternativeType</tt></td>
<td class="topAlign"><tt>3</tt></td>
<td class="topAlign">corresponds to the "multipart/alternative"
subtype, meaning the body parts are alternative representations of
the same information, as described in RFC 2046.</td>
</tr>
</table>
<p><b>See also</b> <a href="qhttpmultipart.html#setContentType">setContentType</a>().</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QHttpMultiPart" />QHttpMultiPart.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qhttpmultipart.html">QHttpMultiPart</a>
with content type <a href="qhttpmultipart.html#ContentType-enum">MixedType</a> and sets
<i>parent</i> as the parent object.</p>
<p><b>See also</b> <a href="qhttpmultipart.html#ContentType-enum">QHttpMultiPart.ContentType</a>.</p>


<h3 class="fn"><a name="QHttpMultiPart-2" />QHttpMultiPart.__init__ (<i>self</i>, <a href="qhttpmultipart.html#ContentType-enum">ContentType</a>&#160;<i>contentType</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qhttpmultipart.html">QHttpMultiPart</a>
with content type <i>contentType</i> and sets parent as the parent
object.</p>
<p><b>See also</b> <a href="qhttpmultipart.html#ContentType-enum">QHttpMultiPart.ContentType</a>.</p>


<h3 class="fn"><a name="append" />QHttpMultiPart.append (<i>self</i>, <a href="qhttppart.html">QHttpPart</a>&#160;<i>httpPart</i>)</h3><p>Appends <i>httpPart</i> to this multipart.</p>


<h3 class="fn"><a name="boundary" /><a href="qbytearray.html">QByteArray</a> QHttpMultiPart.boundary (<i>self</i>)</h3><p>returns the boundary.</p>
<p><b>See also</b> <a href="qhttpmultipart.html#setBoundary">setBoundary</a>().</p>


<h3 class="fn"><a name="setBoundary" />QHttpMultiPart.setBoundary (<i>self</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>boundary</i>)</h3><p>Sets the boundary to <i>boundary</i>.</p>
<p>Usually, you do not need to generate a boundary yourself; upon
construction the boundary is initiated with the string
"boundary_.oOo.<a href="index.html">_</a>" followed by random
characters, and provides enough uniqueness to make sure it does not
occur inside the parts itself.</p>
<p><b>See also</b> <a href="qhttpmultipart.html#boundary">boundary</a>().</p>


<h3 class="fn"><a name="setContentType" />QHttpMultiPart.setContentType (<i>self</i>, <a href="qhttpmultipart.html#ContentType-enum">ContentType</a>&#160;<i>contentType</i>)</h3><p>Sets the content type to <i>contentType</i>. The content type
will be used in the HTTP header section when sending the multipart
message via <a href="qnetworkaccessmanager.html#post">QNetworkAccessManager.post</a>().
In case you want to use a multipart subtype not contained in
<a href="qhttpmultipart.html#ContentType-enum">QHttpMultiPart.ContentType</a>,
you can add the "Content-Type" header field to the <a href="qnetworkrequest.html">QNetworkRequest</a> by hand, and then use
this request together with the multipart message for posting.</p>
<p><b>See also</b> <a href="qhttpmultipart.html#ContentType-enum">QHttpMultiPart.ContentType</a>
and <a href="qnetworkaccessmanager.html#post">QNetworkAccessManager.post</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.9.5-9eb6aac99275 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.3</td></tr></table></div></address></body></html>